﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Windows.Forms;

namespace GameDevelopHelper.Configer
{
    class ProjectConfigerWrapper
    {
        private static ProjectConfiger m_Project = new ProjectConfiger();
        private static string m_strPath = Application.StartupPath + "\\Projects\\ProjectList.xml";
        static ProjectConfigerWrapper()
        {
            m_Project.ReadXml(m_strPath);
        }

        /// <summary>
        /// 获取项目列表
        /// </summary>
        /// <returns></returns>
        public static List<DataRow> GetProjectList()
        {
            List<DataRow> lstProjectList = new List<DataRow>();
            foreach (DataRow row in m_Project.Tables["project"].Rows)
            {
                lstProjectList.Add(row);
            }

            return lstProjectList;
        }

        /// <summary>
        /// 删除项目
        /// </summary>
        /// <param name="row"></param>
        /// <returns></returns>
        public static bool DelProject(DataRow row)
        {
            try
            {
                if (row == null)
                {
                    return false;
                }

                DataTable tableProject = m_Project.Tables["project"];
                tableProject.Rows.Remove(row);
                tableProject.DataSet.AcceptChanges();
                tableProject.DataSet.WriteXml(m_strPath);
            }
            catch
            {
                return false;
            }

            return true;
        }
    }
}
